@extends('layouts.base')



@section('content')


		    <form class="layui-form" action="" lay-filter="example">
		    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
		    	<input type="hidden" name="id">

		    	<div class="layui-form-item">
				    <label class="layui-form-label">父级节点</label>
				    <div class="layui-input-block">
				    	<select name="pid">
				    		<option value="0">顶级节点</option>
				    		@foreach ($nodeList as $nodes)
				      			<option {{ (isset($node['id']) && $nodes['id'] == $node['id']) ? 'disabled' : '' }} value="{{ $nodes['id'] }}">{{ $nodes['name'] }}</option>
				      		@endforeach
				    	</select>
				    </div>
			  	</div>
			  	<div class="layui-form-item">
				    <label class="layui-form-label">节点名称</label>
				    <div class="layui-input-block">
				      	<input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入节点名称" class="layui-input">
				    </div>
			  	</div>
			  	<div class="layui-form-item">
				    <label class="layui-form-label">路由名称</label>
				    <div class="layui-input-block">
				      	<input type="text" name="route" lay-verify="required" autocomplete="off" placeholder="请输入路由名称" class="layui-input">
				    </div>
			  	</div>
			  	<div class="layui-form-item">
				    <label class="layui-form-label">排序</label>
				    <div class="layui-input-block">
				      	<input type="text" name="sort" autocomplete="off" placeholder="请输入排序" class="layui-input">
				    </div>
			  	</div>

			  
			  	<div class="layui-form-item">
			    	<label class="layui-form-label">是否应用菜单</label>
			    	<div class="layui-input-block">
			      		<input type="checkbox" name="is_menu" lay-skin="switch" lay-text="ON|OFF">
			    	</div>
			  	</div>

			  	<div class="layui-form-item layui-form-text">
				    <label class="layui-form-label">说明</label>
				    <div class="layui-input-block">
				      	<textarea placeholder="请输入内容" class="layui-textarea" name="remark"></textarea>
				    </div>
			  	</div>
			 
			  	<div class="layui-form-item">
				    <div class="layui-input-block">
				      	<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
				    </div>
			  	</div>
			</form>

@endsection

@section('script')

	<script type="text/javascript">
		layui.use(['form', 'layedit', 'laydate'], function() {
			var form = layui.form, layer = layui.layer, layedit = layui.layedit, laydate = layui.laydate;
			//监听提交
		  	form.on('submit(demo1)', function(data){
		  		data.field.is_menu = data.field.is_menu == 'on' ? 1 : 0
		    	// layer.alert(JSON.stringify(data.field), {
		     //  		title: '最终的提交信息'
		    	// })
		    	$.post("{{ url('admin/nodes/save') }}", data.field, function(result) {
		    		if (result.code == 0) {
		    			layer.msg(result.msg, {icon: 1, time: 1000}, function() {
		    				parent.location.reload();
		    			})
		    		} else {
		    			layer.msg(result.msg, {icon: 2, time: 1000})
		    		}
		    	})
		    	return false;
		  	});

		  	//表单初始赋值
			form.val('example', @json($node))
		})
	</script>

@endsection